package com.ruge.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 重写 429 限流返回值
 *
 * @author ruge.wu
 * @since 2021/12/2 15:17
 */
@Component
public class RateLimiterFinter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpResponse response = exchange.getResponse();
        return chain.filter(exchange);
    }

    /**
     * @return 网关过滤器的排序，数字越小优先级越高
     */
    @Override
    public int getOrder() {
        return 99;
    }
}
